package com.longteng.diamond.service;


import com.longteng.diamond.domain.ProjectShareNode;
import com.longteng.diamond.factory.ProjectShareFactory;
import com.longteng.diamond.po.RequestResult;
import com.longteng.diamond.po.TablePage;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * Created by Administrator
 * DATE : 2018/7/23
 * TIME : 22:10
 * PROJECT : java-lesson
 * PACKAGE : com.longteng.lesson
 *
 * @author <a href="mailto:taki@qq.com">Administrator</a>
 */
@Component
public  class ProjectShareService {


    @Autowired
    ProjectShareFactory projectShareFactory;

    /**
     * 项目:模块、host、成员列表数据
     * @param projectShareNode
     * @return TablePage
     */
    public TablePage getTableData(ProjectShareNode projectShareNode) {
        int shareType = projectShareNode.getShareType();
        long total =  projectShareFactory.baseMapper(shareType).queryAllRow(projectShareNode);
        List<ProjectShareNode> projectShareNodeList = projectShareFactory.baseMapper(shareType).getProjectShareNode(projectShareNode);
        TablePage tablePage = new TablePage();
        tablePage.setRows(projectShareNodeList);
        tablePage.setTotal(total);
        return tablePage;
    }
    /**
     * 根据id获取模块、host、成员
     * @param projectShareNode
     * @return TablePage
     */
    public ProjectShareNode findProjectShareNodeById(ProjectShareNode projectShareNode) {
        return projectShareFactory.baseMapper(projectShareNode.getShareType()).findProjectShareNodeById(projectShareNode.getId());
    }
    /**
     * 新增模块、host、成员
     * @param projectShareNode
     * @return TablePage
     */
    public void addProjectShare(ProjectShareNode projectShareNode){
        projectShareFactory.projectShareInterface(projectShareNode.getShareType()).addProjectShare(projectShareNode);
    }
    /**
     * 修改模块、host、成员
     * @param projectShareNode
     * @return TablePage
     */
    public void updateProjectShare(ProjectShareNode projectShareNode){
        projectShareFactory.projectShareInterface(projectShareNode.getShareType()).updateProjectShare(projectShareNode);
    }
    /**
     * 删除模块、host、成员
     * @param shareType
     * @param id
     * @return
     */
    public void deleteProjectShare(Integer shareType, Integer id){
       projectShareFactory.projectShareInterface(shareType).deleteProjectShare(id);
    }
    /**
     * 校验模块、host、成员是否绑定
     * @param shareType
     * @param id
     * @return RequestResult
     */
    public RequestResult  deleteProjectShareCheck(Integer shareType, Integer id){
        RequestResult requestResult=  projectShareFactory.projectShareInterface(shareType).deleteProjectShareCheck(id);
        return requestResult;
    }

}
